package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.business.domain.HistoricActivity;
import com.ruoyi.business.domain.TPotentialCustomer;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TFollowUpRecord;
import com.ruoyi.business.service.ITFollowUpRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 跟进记录Controller
 * 
 * @author ruoyi
 * @date 2021-07-26
 */
@Controller
@RequestMapping("/business/record")
public class TFollowUpRecordController extends BaseController
{
    private String prefix = "business/record";

    @Autowired
    private ITFollowUpRecordService tFollowUpRecordService;

    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询跟进记录列表
     */
    @RequiresPermissions("business:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TFollowUpRecord tFollowUpRecord)
    {
        startPage();
        List<TFollowUpRecord> list = tFollowUpRecordService.selectTFollowUpRecordList(tFollowUpRecord);
        return getDataTable(list);
    }

    /**
     * 导出跟进记录列表
     */
    @RequiresPermissions("business:record:export")
    @Log(title = "跟进记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TFollowUpRecord tFollowUpRecord)
    {
        List<TFollowUpRecord> list = tFollowUpRecordService.selectTFollowUpRecordList(tFollowUpRecord);
        ExcelUtil<TFollowUpRecord> util = new ExcelUtil<TFollowUpRecord>(TFollowUpRecord.class);
        return util.exportExcel(list, "跟进记录数据");
    }

    /**
     * 新增跟进记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存跟进记录
     */
    @RequiresPermissions("business:record:add")
    @Log(title = "跟进记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TFollowUpRecord tFollowUpRecord)
    {
        return toAjax(tFollowUpRecordService.insertTFollowUpRecord(tFollowUpRecord));
    }

    /**
     * 修改跟进记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TFollowUpRecord tFollowUpRecord = tFollowUpRecordService.selectTFollowUpRecordById(id);
        mmap.put("tFollowUpRecord", tFollowUpRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存跟进记录
     */
    @RequiresPermissions("business:record:edit")
    @Log(title = "跟进记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TFollowUpRecord tFollowUpRecord)
    {
        return toAjax(tFollowUpRecordService.updateTFollowUpRecord(tFollowUpRecord));
    }





    @RequestMapping("/genjin")
    public String genjin(String id,ModelMap mmap){

        mmap.put("id",id);
        return prefix+"/genjin";
    }

    @PostMapping("/genjinup")
    @ResponseBody
    public AjaxResult genjinup(TFollowUpRecord tFollowUpRecord)
    {
        return toAjax(tFollowUpRecordService.updateTFollowUpRecord(tFollowUpRecord));
    }

    @RequestMapping("/his")
    public String historyPage(String id,ModelMap mmap){

        mmap.put("id",id);

        return prefix+"/his";
    }


    @RequestMapping("/hisList")
    @ResponseBody
    public TableDataInfo listHistory(String id){
        List<TFollowUpRecord> list= tFollowUpRecordService.selectCustomer(id);
        return getDataTable(list);

    }

    @GetMapping( "/remove")
    @ResponseBody
    public AjaxResult remove1(String id)
    {
        return toAjax(tFollowUpRecordService.deleteById(Long.parseLong(id)));
    }

}
